'''
Descripttion: 
version: 
Author: Born
Date: 2020-02-16 14:03:51
LastEditors: Born
'''


# Create your models here.
from django.db import models
from DataCenter.code import Code
from gxdm.models import *
from DataCenter.model import System


class DataDictionaryDirectory(models.Model):
    id = models.CharField(primary_key=True, max_length=128, verbose_name='编号')
    table_schema = models.CharField('库名', db_column='TABLE_SCHEMA', max_length=64)  # Field name made lowercase.
    schema_comment = models.CharField('库注释', db_column='SCHEMA_COMMENT', max_length=255, blank=True, null=True)
    table_name = models.CharField('表名', db_column='TABLE_NAME', max_length=64)  # Field name made lowercase.
    table_comment = models.CharField('表注释', db_column='TABLE_COMMENT', max_length=2048, blank=True, null=True)  # Field name made lowercase.
    column_name = models.CharField('字段名', db_column='COLUMN_NAME', max_length=64)  # Field name made lowercase.
    column_comment = models.CharField('字段注释', db_column='COLUMN_COMMENT', max_length=1024)  # Field name made lowercase.
    column_type = models.TextField('字段类型', db_column='COLUMN_TYPE')  # Field name made lowercase.
    is_nullable = models.CharField('允许为空', db_column='IS_NULLABLE', max_length=3)  # Field name made lowercase.
    column_default = models.TextField('默认值', db_column='COLUMN_DEFAULT', blank=True, null=True)  # Field name made lowercase.
    extra = models.CharField('其它', db_column='EXTRA', max_length=30)  # Field name made lowercase.

    class Meta:
        managed = False  # Created from a view. Don't remove.
        db_table = 'data_dictionary_directory'
        verbose_name = '字段目录'
        verbose_name_plural = '字段目录'


class FieldMetaInfo(models.Model):
    id = models.OneToOneField(DataDictionaryDirectory, to_field='id', on_delete=models.PROTECT, related_name='field_meta', db_column='id', verbose_name='编号', primary_key=True)
    department = models.ForeignKey(Dwbmdm, verbose_name='管理部门', db_column='department', to_field='value', blank=True, null=True, on_delete=models.PROTECT)
    system = models.ForeignKey(System, verbose_name='来源系统', db_column='system', blank=True, null=True, on_delete=models.PROTECT)
    maintainer = models.CharField('维护员', max_length=32, blank=True, null=True)
    remarks = models.CharField('备注', max_length=255, blank=True, null=True)
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    update_time = models.DateTimeField("更新时间", auto_now=True)

    class Meta:
        managed = False
        db_table = 'field_meta_info'
        verbose_name = '字段元信息'
        verbose_name_plural = '字段元信息'


class RemovedUser(models.Model):
    class Meta:
        managed = False
        db_table = 'removed_user'
        verbose_name = '疫情防控填报剔除名单'
        verbose_name_plural = '疫情防控填报剔除名单'

    xgh = models.CharField('学工号', max_length=64, primary_key=True)


class BaseModel(models.Model):
    class Meta:
        abstract = True
        managed = False


class Others(BaseModel):
    class Meta(BaseModel.Meta):
        db_table = 'zc_user'
        verbose_name = '校外人员信息'
        verbose_name_plural = '校外人员信息'

    xgh = models.CharField('学工号', max_length=50, unique=True, primary_key=True)
    xm = models.CharField('姓名', max_length=100)
    # xb = models.CharField("性别", max_length=1, choices=Code.SEX_CHOICE, blank=True, null=True)
    xb = models.ForeignKey(Xbdm, to_field='value', db_column='xb', on_delete=models.PROTECT, blank=True, null=True, verbose_name='性别')
    # sfzjlxm = models.CharField('身份证件类型', choices=Code.IDCARD_TYPE_CHOICE, max_length=100)
    sfzjlxm = models.ForeignKey(Sfzjlxdm, to_field='value', db_column='sfzjlxm', on_delete=models.PROTECT, blank=True, null=True, verbose_name='身份证件类型')
    sfzjh = models.CharField('身份证件号', max_length=100, blank=True, null=True)
    bjbh = models.CharField('班级编号', max_length=100, blank=True, null=True)
    bjmc = models.CharField('班级名称', max_length=100, blank=True, null=True)
    zybh = models.CharField('专业编号', max_length=100, blank=True, null=True)
    type = models.CharField('用户类型1', max_length=100, blank=True, null=True)
    type_2 = models.CharField('用户类型2', max_length=100, blank=True, null=True)
    ssjgbh = models.CharField('所属机构编号', max_length=100, blank=True, null=True)
    ssjg = models.CharField('所属机构', max_length=100, blank=True, null=True)
    # glbm = models.CharField('管理部门', choices=Code.DEPARTMENT_CHOICE, max_length=100)
    glbm = models.ForeignKey(Dwbmdm, to_field='value', db_column='glbm', null=True, blank=True, verbose_name='管理部门', on_delete=models.PROTECT)
    yddh = models.CharField('移动电话', max_length=100, blank=True, null=True)
    remark = models.CharField('备注', max_length=100, blank=True, null=True)
    cjsj = models.DateTimeField('创建时间')

    def __str__(self):
        return self.xm







